﻿using System;
using System.Configuration;
using System.Data;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace dcwj
{
    public partial class router : System.Web.UI.Page
    {
        private String M_CONSTR = ConfigurationManager.ConnectionStrings["dcwjConnectionString"].ToString();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["paperid"] != null)
                {
                    string pid = Request["paperid"].ToString();
                    string viewrs = Request["viewrs"].ToString();
                    string viewdata = string.Empty;

                    if (Request["viewdata"] != null)
                    {
                        viewdata = Request["viewdata"].ToString();
                    }                    

                    if (!string.IsNullOrEmpty(pid))
                    {
                        Database objDB = new SqlDatabase(M_CONSTR);
                        if (objDB != null)
                        {
                            DataSet ds = objDB.ExecuteDataSet(CommandType.Text,
                                    @"SELECT * FROM Table_PAPER WHERE PAPERID=" + pid);
                            if (ds != null && ds.Tables[0].Rows.Count.Equals(1))
                            {
                                string pType = ds.Tables[0].Rows[0]["PaperClassID"].ToString();

                                if (pType.Equals("1"))//完整版问卷
                                {
                                    if (!string.IsNullOrEmpty(viewrs))
                                    {
                                        if (!string.IsNullOrEmpty(viewdata))
                                        {
                                            Response.Redirect("~/report/dbbgdata.aspx?paperid=" + pid + "&viewdata=true");
                                        }
                                        Response.Redirect("~/report/dbbg.aspx?paperid=" + pid);
                                    }
                                    Response.Redirect("wz.aspx?paperid=" + pid);
                                }
                                else if (pType.Equals("2"))//讲师版问卷
                                {
                                    if (!string.IsNullOrEmpty(viewrs))
                                    {
                                        if (!string.IsNullOrEmpty(viewdata))
                                        {
                                            Response.Redirect("~/report/jsbgdata.aspx?paperid=" + pid + "&viewdata=true");
                                        }
                                        Response.Redirect("~/report/NotAllow.aspx");
                                    }
                                    Response.Redirect("js.aspx?paperid=" + pid);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}